Instead of falling back to a set of default values or crashing the
window manager when an invalid mode is specified, check the value
of the ShellGlobal:session-mode property before taking over as WM
and make a clean exit if it cannot be resolved to an existent mode.
https://bugzilla.gnome.org/show_bug.cgi?id=676156
'user': { sessionType: Shell.SessionType.USER }
};
+function modeExists(mode) {
+ let modes = Object.getOwnPropertyNames(_modes);
+ return modes.indexOf(mode) != -1;
+}
+
const SessionMode = new Lang.Class({
Name: 'SessionMode',
_shell_global_init ("session-mode", session_mode, NULL);
+ if (!_shell_global_has_valid_session_mode (shell_global_get ()))
+ {
+ g_printerr ("\"%s\" is not a valid mode.\n", session_mode);
+ exit(1);
+ }
+
ecode = meta_run ();
if (g_getenv ("GNOME_SHELL_ENABLE_CLEANUP"))
GjsContext *_shell_global_get_gjs_context (ShellGlobal *global);
+gboolean _shell_global_has_valid_session_mode (ShellGlobal *global);
gboolean _shell_global_check_xdnd_event (ShellGlobal *global,
XEvent *xev);
}
}
+gboolean
+_shell_global_has_valid_session_mode (ShellGlobal *global)
+{
+ char *script;
+ int status;
+
+ script = g_strdup_printf ("imports.ui.environment.init();"
+ "imports.ui.sessionMode.modeExists('%s') || 1;",
+ global->session_mode);
+ gjs_context_eval (global->js_context, script, -1, "<sessionMode.js>", &status, NULL);
+ g_free (script);
+
+ return status == 0;
+}
+
/**
* shell_global_set_cursor:
* @global: A #ShellGlobal